//
//  HZDataTool.m
//  HZTC_Stock
//
//  Created by MayerF on 17/3/17.
//  Copyright © 2017年 MayerF. All rights reserved.
//

#import "HZDataTool.h"
#import "HZOwnedStockModel.h"
#import "HZMinPriceModel.h"
#import "FileTools.h"

#import "QuoteLvOper.h"
extern QUOTELV_OPER *g_pQuoteOper;

@implementation HZDataTool

+ (BOOL)getIsRStockWithCodeInfo:(HZOwnedStockModel *)codeInfo
{
    BOOL isR = NO;
    FILE_DATA* f_data = FileTools_ReadDataEx("bdzq.data");
    if (f_data == NULL) {
        return isR;
    }
    NSString *source = [[NSString alloc] initWithData:[NSData dataWithBytes:f_data->pData length:f_data->nSize] encoding:NSUTF8StringEncoding];
    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[NSData dataWithBytes:f_data->pData length:f_data->nSize] options:NSJSONReadingMutableContainers error:nil];
    
    NSString *key = [NSString stringWithFormat:@"%d",codeInfo.nModel_Market];
    if ([dict.allKeys containsObject:key]) {
        NSArray *array = [dict valueForKey:key];
        if ([array containsObject:codeInfo.model_Code]) {
            isR = YES;
            return isR;
        }
    }
    
    return isR;
}

+ (void)dataToModelWithApiType:(kHZApiType)apiType
                       success:(void(^)(id model, kHZApiType apiType))success
{
    id models = nil;
    switch (apiType) {
        case kHZApi_Own_Type:
        {
            models = [self p_parseOwnData];
        }
            break;
        case kHZApi_BlockIndex_Type:
        {
            models = [self p_parseBlockIndexData];
        }
            break;
        case kHZApi_ZhangFuTop_Type:
        {
            models = [self p_parseZhangFuTopData];
        }
            break;
        case kHZApi_HuanShouTop_Type:
        {
            models = [self p_parseHuanShouTopData];
        }
            break;
        case kHZApi_LiangBiTop_Type:
        {
            models = [self p_parseLiangBiTopData];
        }
            break;
        case kHZApi_GaiNian_Type:
        {
            models = [self p_parseGaiNianData];
        }
            break;
        case kHZApi_HangYe_Type:
        {
            models = [self p_parseHangYeData];
        }
            break;
        case kHZApi_Zone_Type:
        {
            models = [self p_parseZoneData];
        }
            break;
        case kHZApi_ZhangFuTop_CY_Type:
        {
            models = [self p_parseCYZhangFuTopData];
        }
            break;
        case kHZApi_HuanShouTop_CY_Type:
        {
            models = [self p_parseCYHuanShouTopData];
        }
            break;
        case kHZApi_LiangBiTop_CY_Type:
        {
            models = [self p_parseCYLiangBiTopData];
        }
            break;
        case kHZApi_HuGangTong_Type:
        {
            models = [self p_parseHuGangTongData];
        }
            break;
        case kHZApi_ShenGangTong_Type:
        {
            models = [self p_parseShenGangTongData];
        }
            break;
        case kHZApi_HuGuTong_Type:
        {
            models = [self p_parseHuGuTongData];
        }
            break;
        case kHZApi_ShenGuTong_Type:
        {
            models = [self p_parseShenGuTongData];
        }
            break;
        case kHZApi_MinPrice_Type:
        {
            models = [self p_parseMinPriceData];
        }
            break;
        case kHZApi_MinDetail_Type:
        {
            models = [self p_parseMingXiData];
        }
            break;
        case kHZApi_IndexZhangFuTop_Type:
        {
            models = [self p_parseIndexZhangFuTopData];
        }
            break;
        case kHZApi_IndexDieFuTop_Type:
        {
            models = [self p_parseIndexDieFuTopData];
        }
            break;
        case kHZApi_IndexHuanShouTop_Type:
        {
            models = [self p_parseIndexHuanShouTopData];
        }
            break;
        case kHZApi_Min_Type:
        {
            [self p_parseMinData];
        }
            break;
        case kHZApi_KLine_Type:
        {
            models = [self p_parseKLineData];
        }
            break;
            
        default:
            break;
    }
    success(models, apiType);
}

//自选股
+ (id)p_parseOwnData
{
    QUOTELV_OWN_RES	*pOwnRes = &g_pQuoteOper->OwnRes[QUOTELV_OPER_TAG_OWN];

    NSMutableArray *pTempArray = [NSMutableArray array];
    for (int i = 0; i < pOwnRes->nTotalCount; i++) {
        QUOTELV_STOCK_POINT *pPoint = &pOwnRes->ownData[i];
        HZOwnedStockModel *model = [HZOwnedStockModel new];
        model.model_Name = [NSString stringWithUTF8String:pPoint->codeinfo.name];
        model.model_Code = [NSString stringWithUTF8String:pPoint->codeinfo.code];
        model.nModel_Market = pPoint->codeinfo.market;
        model.nModel_Style = pPoint->codeinfo.style;
        model.model_Price = D_PriShow(pPoint->fCur,pPoint->codeinfo.decNum);
        model.model_ZhangDie = D_PriShowE(pPoint->fCur,pPoint->fPre,pPoint->codeinfo.decNum);
        model.model_ZhangFu = DRShow(pPoint->fCur, pPoint->fPre);
        model.model_Color = kMYGetZhangDieColor(pPoint->fCur, pPoint->fPre);
        NSString *pCode = [NSString stringWithUTF8String:pPoint->codeinfo.code];
        if (pPoint->codeinfo.market == 6) {//港股
            model.model_Code = [pCode stringByAppendingString:@"(港)"];
        }else if (pPoint->codeinfo.market == 24) {//沪港通
            model.model_Code = [pCode stringByAppendingString:@"(沪)"];
        }else {
            model.model_Code = pCode;
        }
        [pTempArray addObject:model];
    }
    
    return pTempArray;
}
//板块okex
+ (id)p_parseBlockIndexData
{
    QUOTELV_INDEX_RES *pIndexRes = &g_pQuoteOper->IndexRes[QUOTELV_OPER_TAG_INDEX];
    
    NSMutableArray *pTempArray = [NSMutableArray array];
    for (int i = 0; i < pIndexRes->nTotalCount; i++) {
        if (i > 4) { break;}
        QUOTELV_STOCK_POINT *pPoint = &pIndexRes->indexData[i];
        if(([[NSString stringWithUTF8String:pPoint->codeinfo.code] isEqualToString:@"399305"])
           ||([[NSString stringWithUTF8String:pPoint->codeinfo.code] isEqualToString:@"1B0008"])
           ||([[NSString stringWithUTF8String:pPoint->codeinfo.code] isEqualToString:@"399003"])
           ||([[NSString stringWithUTF8String:pPoint->codeinfo.code] isEqualToString:@"399002"]))
        {
            continue;
        }
        
        HZOwnedStockModel *model = [HZOwnedStockModel new];
        model.model_Name = [NSString stringWithUTF8String:pPoint->codeinfo.name];
        model.model_Code = [NSString stringWithUTF8String:pPoint->codeinfo.code];
        model.nModel_Market = pPoint->codeinfo.market;
        model.nModel_Style = pPoint->codeinfo.style;
        model.model_Price = D_PriShow(pPoint->fCur,pPoint->codeinfo.decNum);
        model.model_ZhangDie = D_PriShowE(pPoint->fCur,pPoint->fPre,pPoint->codeinfo.decNum);
        model.model_ZhangFu = DRShow(pPoint->fCur, pPoint->fPre);
        if ([model.model_ZhangFu floatValue] > 0) {
            model.model_ZhangFu = [NSString stringWithFormat:@"+%@", model.model_ZhangFu];
        }
        model.model_Color = kMYGetZhangDieColor(pPoint->fCur, pPoint->fPre);
        model.model_SpecialColor = model.model_Color;
        [pTempArray addObject:model];
    }
    
    return pTempArray;
}
//涨幅榜
+ (id)p_parseZhangFuTopData
{
    QUOTELV_BLOCK_RES *pBlockRes = &g_pQuoteOper->BlockRes[QUOTELV_OPER_TAG_HS_ZF];
    
    NSMutableArray *pTempArray = [NSMutableArray array];
    for (int i=0; i<pBlockRes->nTotalCount; i++) {
        QUOTELV_STOCK_POINT *pPoint = &pBlockRes->blockData[i];
        HZOwnedStockModel *model = [HZOwnedStockModel new];
        model.model_Name = [NSString stringWithUTF8String:pPoint->codeinfo.name];
        model.model_Code = [NSString stringWithUTF8String:pPoint->codeinfo.code];
        model.nModel_Market = pPoint->codeinfo.market;
        model.nModel_Style = pPoint->codeinfo.style;
        model.model_Price = D_PriShow(pPoint->fCur,pPoint->codeinfo.decNum);
        model.model_ZhangDie = D_PriShowE(pPoint->fCur,pPoint->fPre,pPoint->codeinfo.decNum);
        model.model_ZhangFu = DRShow(pPoint->fCur, pPoint->fPre);
        if ([model.model_ZhangFu floatValue] > 0) {
            model.model_ZhangFu = [NSString stringWithFormat:@"+%@", model.model_ZhangFu];
        }
        model.model_Color = kMYGetZhangDieColor(pPoint->fCur, pPoint->fPre);
        model.model_SpecialColor = model.model_Color;
        [pTempArray addObject:model];
    }
    
    return pTempArray;
}
//换手率榜
+ (id)p_parseHuanShouTopData
{
    QUOTELV_BLOCK_RES *pBlockRes = &g_pQuoteOper->BlockRes[QUOTELV_OPER_TAG_HS_HS];
    
    NSMutableArray *pTempArray = [NSMutableArray array];
    for (int i=0; i<pBlockRes->nTotalCount; i++) {
        QUOTELV_STOCK_POINT *pPoint = &pBlockRes->blockData[i];
        HZOwnedStockModel *model = [HZOwnedStockModel new];
        model.model_Name = [NSString stringWithUTF8String:pPoint->codeinfo.name];
        model.model_Code = [NSString stringWithUTF8String:pPoint->codeinfo.code];
        model.nModel_Market = pPoint->codeinfo.market;
        model.nModel_Style = pPoint->codeinfo.style;
        model.model_Price = D_PriShow(pPoint->fCur,pPoint->codeinfo.decNum);
        model.model_ZhangDie = D_PriShowE(pPoint->fCur,pPoint->fPre,pPoint->codeinfo.decNum);
        model.model_ZhangFu = SwpShow(pPoint->nSwap);                                  //换手率
        model.model_Color = kMYGetZhangDieColor(pPoint->fCur, pPoint->fPre);
        [pTempArray addObject:model];
    }
    
    return pTempArray;
}
//量比榜
+ (id)p_parseLiangBiTopData
{
    QUOTELV_BLOCK_RES *pBlockRes = &g_pQuoteOper->BlockRes[QUOTELV_OPER_TAG_HS_LB];
    
    NSMutableArray *pTempArray = [NSMutableArray array];
    for (int i=0; i<pBlockRes->nTotalCount; i++) {
        QUOTELV_STOCK_POINT *pPoint = &pBlockRes->blockData[i];
        HZOwnedStockModel *model = [HZOwnedStockModel new];
        model.model_Name = [NSString stringWithUTF8String:pPoint->codeinfo.name];
        model.model_Code = [NSString stringWithUTF8String:pPoint->codeinfo.code];
        model.nModel_Market = pPoint->codeinfo.market;
        model.nModel_Style = pPoint->codeinfo.style;
        model.model_Price = D_PriShow(pPoint->fCur,pPoint->codeinfo.decNum);
        model.model_ZhangDie = D_PriShowE(pPoint->fCur,pPoint->fPre,pPoint->codeinfo.decNum);
        model.model_ZhangFu = DRShow(pPoint->fCur, pPoint->fPre);
        model.model_Color = kMYGetZhangDieColor(pPoint->fCur, pPoint->fPre);
        [pTempArray addObject:model];
    }
    
    return pTempArray;
}
//okex跌幅榜
+ (id)p_parseIndexDieFuTopData
{
    QUOTELV_BLOCK_RES *pBlockRes = &g_pQuoteOper->BlockRes[QUOTELV_OPER_TAG_INDEX_DF];
    
    NSMutableArray *pTempArray = [NSMutableArray array];
    for (int i=0; i<pBlockRes->nTotalCount; i++) {
        QUOTELV_STOCK_POINT *pPoint = &pBlockRes->blockData[i];
        HZOwnedStockModel *model = [HZOwnedStockModel new];
        model.model_Name = [NSString stringWithUTF8String:pPoint->codeinfo.name];
        model.model_Code = [NSString stringWithUTF8String:pPoint->codeinfo.code];
        model.nModel_Market = pPoint->codeinfo.market;
        model.nModel_Style = pPoint->codeinfo.style;
        model.model_Price = D_PriShow(pPoint->fCur,pPoint->codeinfo.decNum);
        model.model_ZhangDie = D_PriShowE(pPoint->fCur,pPoint->fPre,pPoint->codeinfo.decNum);
        model.model_ZhangFu = DRShow(pPoint->fCur, pPoint->fPre);
        model.model_Color = kMYGetZhangDieColor(pPoint->fCur, pPoint->fPre);
        model.model_SpecialColor = model.model_Color;
        [pTempArray addObject:model];
    }
    
    return pTempArray;
}
//okex涨幅榜
+ (id)p_parseIndexZhangFuTopData
{
    QUOTELV_BLOCK_RES *pBlockRes = &g_pQuoteOper->BlockRes[QUOTELV_OPER_TAG_INDEX_ZF];
    
    NSMutableArray *pTempArray = [NSMutableArray array];
    for (int i=0; i<pBlockRes->nTotalCount; i++) {
        QUOTELV_STOCK_POINT *pPoint = &pBlockRes->blockData[i];
        HZOwnedStockModel *model = [HZOwnedStockModel new];
        model.model_Name = [NSString stringWithUTF8String:pPoint->codeinfo.name];
        model.model_Code = [NSString stringWithUTF8String:pPoint->codeinfo.code];
        model.nModel_Market = pPoint->codeinfo.market;
        model.nModel_Style = pPoint->codeinfo.style;
        model.model_Price = D_PriShow(pPoint->fCur,pPoint->codeinfo.decNum);
        model.model_ZhangDie = D_PriShowE(pPoint->fCur,pPoint->fPre,pPoint->codeinfo.decNum);
        model.model_ZhangFu = DRShow(pPoint->fCur, pPoint->fPre);
        model.model_Color = kMYGetZhangDieColor(pPoint->fCur, pPoint->fPre);
        model.model_SpecialColor = model.model_Color;
        [pTempArray addObject:model];
    }
    
    return pTempArray;
}
//okex换手率榜
+ (id)p_parseIndexHuanShouTopData
{
    QUOTELV_BLOCK_RES *pBlockRes = &g_pQuoteOper->BlockRes[QUOTELV_OPER_TAG_INDEX_HS];
    
    NSMutableArray *pTempArray = [NSMutableArray array];
    for (int i=0; i<pBlockRes->nTotalCount; i++) {
        QUOTELV_STOCK_POINT *pPoint = &pBlockRes->blockData[i];
        HZOwnedStockModel *model = [HZOwnedStockModel new];
        model.model_Name = [NSString stringWithUTF8String:pPoint->codeinfo.name];
        model.model_Code = [NSString stringWithUTF8String:pPoint->codeinfo.code];
        model.nModel_Market = pPoint->codeinfo.market;
        model.nModel_Style = pPoint->codeinfo.style;
        model.model_Price = D_PriShow(pPoint->fCur,pPoint->codeinfo.decNum);
        model.model_ZhangDie = D_PriShowE(pPoint->fCur,pPoint->fPre,pPoint->codeinfo.decNum);
        model.model_ZhangFu = SwpShow(pPoint->nSwap);//换手率
        model.model_Color = kMYGetZhangDieColor(pPoint->fCur, pPoint->fPre);
        [pTempArray addObject:model];
    }
    
    return pTempArray;
}
//概念板块
+ (id)p_parseGaiNianData
{
    QUOTELV_BLOCK_RES *pBlockRes = &g_pQuoteOper->BlockRes[QUOTELV_OPER_TAG_BLOCK_CONCEPT];
    
    NSMutableArray *pTempArray = [NSMutableArray array];
    for (int i=0; i<pBlockRes->nTotalCount; i++) {
        QUOTELV_STOCK_POINT *pPoint = &pBlockRes->blockData[i];
        HZOwnedStockModel *model = [HZOwnedStockModel new];
        model.model_Name = [NSString stringWithUTF8String:pPoint->codeinfo.name];
        model.model_Code = [NSString stringWithUTF8String:pPoint->codeinfo.code];
        model.nModel_Market = pPoint->codeinfo.market;
        model.nModel_Style = pPoint->codeinfo.style;
        model.nModel_BlockId = pPoint->BlockId;
        model.model_Price = D_PriShow(pPoint->fCur,pPoint->codeinfo.decNum);
        model.model_ZhangDie = D_PriShowE(pPoint->fCur,pPoint->fPre,pPoint->codeinfo.decNum);
        model.model_ZhangFu = DRShow(pPoint->fCur, pPoint->fPre);
        if ([model.model_ZhangFu floatValue] > 0) {
            model.model_ZhangFu = [NSString stringWithFormat:@"+%@", model.model_ZhangFu];
        }
        model.model_Color = kMYGetZhangDieColor(pPoint->fCur, pPoint->fPre);
        [pTempArray addObject:model];
    }
    
    return pTempArray;
}
//行业板块
+ (id)p_parseHangYeData
{
    QUOTELV_BLOCK_RES *pBlockRes = &g_pQuoteOper->BlockRes[QUOTELV_OPER_TAG_BLOCK_INDUSTRY];
    
    NSMutableArray *pTempArray = [NSMutableArray array];
    for (int i=0; i<pBlockRes->nTotalCount; i++) {
        QUOTELV_STOCK_POINT *pPoint = &pBlockRes->blockData[i];
        HZOwnedStockModel *model = [HZOwnedStockModel new];
        model.model_Name = [NSString stringWithUTF8String:pPoint->codeinfo.name];
        model.model_Code = [NSString stringWithUTF8String:pPoint->codeinfo.code];
        model.nModel_Market = pPoint->codeinfo.market;
        model.nModel_Style = pPoint->codeinfo.style;
        model.nModel_BlockId = pPoint->BlockId;
        model.model_Price = D_PriShow(pPoint->fCur,pPoint->codeinfo.decNum);
        model.model_ZhangDie = D_PriShowE(pPoint->fCur,pPoint->fPre,pPoint->codeinfo.decNum);
        model.model_ZhangFu = DRShow(pPoint->fCur, pPoint->fPre);
        if ([model.model_ZhangFu floatValue] > 0) {
            model.model_ZhangFu = [NSString stringWithFormat:@"+%@", model.model_ZhangFu];
        }
        model.model_Color = kMYGetZhangDieColor(pPoint->fCur, pPoint->fPre);
        [pTempArray addObject:model];
    }
    
    return pTempArray;
}
//地区板块
+ (id)p_parseZoneData
{
    QUOTELV_BLOCK_RES *pBlockRes = &g_pQuoteOper->BlockRes[QUOTELV_OPER_TAG_BLOCK_AREA];
    
    NSMutableArray *pTempArray = [NSMutableArray array];
    for (int i=0; i<pBlockRes->nTotalCount; i++) {
        QUOTELV_STOCK_POINT *pPoint = &pBlockRes->blockData[i];
        HZOwnedStockModel *model = [HZOwnedStockModel new];
        model.model_Name = [NSString stringWithUTF8String:pPoint->codeinfo.name];
        model.model_Code = [NSString stringWithUTF8String:pPoint->codeinfo.code];
        model.nModel_Market = pPoint->codeinfo.market;
        model.nModel_Style = pPoint->codeinfo.style;
        model.nModel_BlockId = pPoint->BlockId;
        model.model_Price = D_PriShow(pPoint->fCur,pPoint->codeinfo.decNum);
        model.model_ZhangDie = D_PriShowE(pPoint->fCur,pPoint->fPre,pPoint->codeinfo.decNum);
        model.model_ZhangFu = DRShow(pPoint->fCur, pPoint->fPre);
        if ([model.model_ZhangFu floatValue] > 0) {
            model.model_ZhangFu = [NSString stringWithFormat:@"+%@", model.model_ZhangFu];
        }
        model.model_Color = kMYGetZhangDieColor(pPoint->fCur, pPoint->fPre);
        [pTempArray addObject:model];
    }
    
    return pTempArray;
}
//创业涨幅榜
+ (id)p_parseCYZhangFuTopData
{
    QUOTELV_BLOCK_RES *pBlockRes = &g_pQuoteOper->BlockRes[QUOTELV_OPER_TAG_CYB_ZF];
    
    NSMutableArray *pTempArray = [NSMutableArray array];
    for (int i=0; i<pBlockRes->nTotalCount; i++) {
        QUOTELV_STOCK_POINT *pPoint = &pBlockRes->blockData[i];
        HZOwnedStockModel *model = [HZOwnedStockModel new];
        model.model_Name = [NSString stringWithUTF8String:pPoint->codeinfo.name];
        model.model_Code = [NSString stringWithUTF8String:pPoint->codeinfo.code];
        model.nModel_Market = pPoint->codeinfo.market;
        model.nModel_Style = pPoint->codeinfo.style;
        model.model_Price = D_PriShow(pPoint->fCur,pPoint->codeinfo.decNum);
        model.model_ZhangDie = D_PriShowE(pPoint->fCur,pPoint->fPre,pPoint->codeinfo.decNum);
        model.model_ZhangFu = DRShow(pPoint->fCur, pPoint->fPre);
        if ([model.model_ZhangFu floatValue] > 0) {
            model.model_ZhangFu = [NSString stringWithFormat:@"+%@", model.model_ZhangFu];
        }
        model.model_Color = kMYGetZhangDieColor(pPoint->fCur, pPoint->fPre);
        model.model_SpecialColor = model.model_Color;
        [pTempArray addObject:model];
    }
    
    return pTempArray;
}
//创业还手榜
+ (id)p_parseCYHuanShouTopData
{
    QUOTELV_BLOCK_RES *pBlockRes = &g_pQuoteOper->BlockRes[QUOTELV_OPER_TAG_CYB_HS];
    
    NSMutableArray *pTempArray = [NSMutableArray array];
    for (int i=0; i<pBlockRes->nTotalCount; i++) {
        QUOTELV_STOCK_POINT *pPoint = &pBlockRes->blockData[i];
        HZOwnedStockModel *model = [HZOwnedStockModel new];
        model.model_Name = [NSString stringWithUTF8String:pPoint->codeinfo.name];
        model.model_Code = [NSString stringWithUTF8String:pPoint->codeinfo.code];
        model.nModel_Market = pPoint->codeinfo.market;
        model.nModel_Style = pPoint->codeinfo.style;
        model.model_Price = D_PriShow(pPoint->fCur,pPoint->codeinfo.decNum);
        model.model_ZhangDie = D_PriShowE(pPoint->fCur,pPoint->fPre,pPoint->codeinfo.decNum);
        model.model_ZhangFu = DRShow(pPoint->fCur, pPoint->fPre);
        model.model_Color = kMYGetZhangDieColor(pPoint->fCur, pPoint->fPre);
        [pTempArray addObject:model];
    }
    
    return pTempArray;
}
//创业量比榜
+ (id)p_parseCYLiangBiTopData
{
    QUOTELV_BLOCK_RES *pBlockRes = &g_pQuoteOper->BlockRes[QUOTELV_OPER_TAG_CYB_LB];
    
    NSMutableArray *pTempArray = [NSMutableArray array];
    for (int i=0; i<pBlockRes->nTotalCount; i++) {
        QUOTELV_STOCK_POINT *pPoint = &pBlockRes->blockData[i];
        HZOwnedStockModel *model = [HZOwnedStockModel new];
        model.model_Name = [NSString stringWithUTF8String:pPoint->codeinfo.name];
        model.model_Code = [NSString stringWithUTF8String:pPoint->codeinfo.code];
        model.nModel_Market = pPoint->codeinfo.market;
        model.nModel_Style = pPoint->codeinfo.style;
        model.model_Price = D_PriShow(pPoint->fCur,pPoint->codeinfo.decNum);
        model.model_ZhangDie = D_PriShowE(pPoint->fCur,pPoint->fPre,pPoint->codeinfo.decNum);
        model.model_ZhangFu = DRShow(pPoint->fCur, pPoint->fPre);
        model.model_Color = kMYGetZhangDieColor(pPoint->fCur, pPoint->fPre);
        [pTempArray addObject:model];
    }
    
    return pTempArray;
}
//沪港通
+ (id)p_parseHuGangTongData
{
    QUOTELV_BLOCK_RES *pBlockRes = &g_pQuoteOper->BlockRes[QUOTELV_OPER_TAG_HK_GGT];
    
    NSMutableArray *pTempArray = [NSMutableArray array];
    for (int i=0; i<pBlockRes->nTotalCount; i++) {
        QUOTELV_STOCK_POINT *pPoint = &pBlockRes->blockData[i];
        HZOwnedStockModel *model = [HZOwnedStockModel new];
        model.model_Name = [NSString stringWithUTF8String:pPoint->codeinfo.name];
        model.model_Code = [NSString stringWithUTF8String:pPoint->codeinfo.code];
        model.nModel_Market = pPoint->codeinfo.market;
        model.nModel_Style = pPoint->codeinfo.style;
        model.model_Price = D_PriShow(pPoint->fCur,pPoint->codeinfo.decNum);
        model.model_ZhangDie = D_PriShowE(pPoint->fCur,pPoint->fPre,pPoint->codeinfo.decNum);
        model.model_ZhangFu = DRShow(pPoint->fCur, pPoint->fPre);
        model.model_Color = kMYGetZhangDieColor(pPoint->fCur, pPoint->fPre);
        model.model_SpecialColor = model.model_Color;
        [pTempArray addObject:model];
    }
    
    return pTempArray;
}
//深港通
+ (id)p_parseShenGangTongData
{
    QUOTELV_BLOCK_RES *pBlockRes = &g_pQuoteOper->BlockRes[QUOTELV_OPER_TAG_HK_MAIN];
    
    NSMutableArray *pTempArray = [NSMutableArray array];
    for (int i=0; i<pBlockRes->nTotalCount; i++) {
        QUOTELV_STOCK_POINT *pPoint = &pBlockRes->blockData[i];
        HZOwnedStockModel *model = [HZOwnedStockModel new];
        model.model_Name = [NSString stringWithUTF8String:pPoint->codeinfo.name];
        model.model_Code = [NSString stringWithUTF8String:pPoint->codeinfo.code];
        model.nModel_Market = pPoint->codeinfo.market;
        model.nModel_Style = pPoint->codeinfo.style;
        model.model_Price = D_PriShow(pPoint->fCur,pPoint->codeinfo.decNum);
        model.model_ZhangDie = D_PriShowE(pPoint->fCur,pPoint->fPre,pPoint->codeinfo.decNum);
        model.model_ZhangFu = DRShow(pPoint->fCur, pPoint->fPre);
        model.model_Color = kMYGetZhangDieColor(pPoint->fCur, pPoint->fPre);
        model.model_SpecialColor = model.model_Color;
        [pTempArray addObject:model];
    }
    
    return pTempArray;
}
//沪股通
+ (id)p_parseHuGuTongData
{
    QUOTELV_BLOCK_RES *pBlockRes = &g_pQuoteOper->BlockRes[QUOTELV_OPER_TAG_HK_CY];
    
    NSMutableArray *pTempArray = [NSMutableArray array];
    for (int i=0; i<pBlockRes->nTotalCount; i++) {
        QUOTELV_STOCK_POINT *pPoint = &pBlockRes->blockData[i];
        HZOwnedStockModel *model = [HZOwnedStockModel new];
        model.model_Name = [NSString stringWithUTF8String:pPoint->codeinfo.name];
        model.model_Code = [NSString stringWithUTF8String:pPoint->codeinfo.code];
        model.nModel_Market = pPoint->codeinfo.market;
        model.nModel_Style = pPoint->codeinfo.style;
        model.model_Price = D_PriShow(pPoint->fCur,pPoint->codeinfo.decNum);
        model.model_ZhangDie = D_PriShowE(pPoint->fCur,pPoint->fPre,pPoint->codeinfo.decNum);
        model.model_ZhangFu = DRShow(pPoint->fCur, pPoint->fPre);
        model.model_Color = kMYGetZhangDieColor(pPoint->fCur, pPoint->fPre);
        model.model_SpecialColor = model.model_Color;
        [pTempArray addObject:model];
    }
    
    return pTempArray;
}
//深股通
+ (id)p_parseShenGuTongData
{
    QUOTELV_BLOCK_RES *pBlockRes = &g_pQuoteOper->BlockRes[QUOTELV_OPER_TAG_HK_INDEX];
    
    NSMutableArray *pTempArray = [NSMutableArray array];
    for (int i=0; i<pBlockRes->nTotalCount; i++) {
        QUOTELV_STOCK_POINT *pPoint = &pBlockRes->blockData[i];
        HZOwnedStockModel *model = [HZOwnedStockModel new];
        model.model_Name = [NSString stringWithUTF8String:pPoint->codeinfo.name];
        model.model_Code = [NSString stringWithUTF8String:pPoint->codeinfo.code];
        model.nModel_Market = pPoint->codeinfo.market;
        model.nModel_Style = pPoint->codeinfo.style;
        model.model_Price = D_PriShow(pPoint->fCur,pPoint->codeinfo.decNum);
        model.model_ZhangDie = D_PriShowE(pPoint->fCur,pPoint->fPre,pPoint->codeinfo.decNum);
        model.model_ZhangFu = DRShow(pPoint->fCur, pPoint->fPre);
        model.model_Color = kMYGetZhangDieColor(pPoint->fCur, pPoint->fPre);
        model.model_SpecialColor = model.model_Color;
        [pTempArray addObject:model];
    }
    
    return pTempArray;
}
//分时报价
+ (id)p_parseMinPriceData
{
    QUOTELV_PRICE_RES *pPriRes = &g_pQuoteOper->PriRes[QUOTELV_OPER_TAG_MIN_PRICE];
    QUOTELV_STOCK_POINT	*priceData = &pPriRes->priceData;
    
    HZMinPriceModel *pMinPriceModel = [HZMinPriceModel new];
    
    pMinPriceModel.model_name = [NSString stringWithUTF8String:priceData->codeinfo.name];
    pMinPriceModel.model_code = [NSString stringWithUTF8String:priceData->codeinfo.code];
    pMinPriceModel.nModel_market = priceData->codeinfo.market;
    pMinPriceModel.model_currentPrice = D_PriShow(pPriRes->priceData.fCur, priceData->codeinfo.decNum);
    pMinPriceModel.model_zhangDie = D_PriShowE(priceData->fCur,priceData->fPre,priceData->codeinfo.decNum);
    pMinPriceModel.model_zhangFu = DRShow(pPriRes->priceData.fCur, pPriRes->priceData.fPre);
    pMinPriceModel.model_maxPrice = D_PriShow(priceData->fHigh,priceData->codeinfo.decNum);
    pMinPriceModel.model_minPrice = D_PriShow(priceData->fLow,priceData->codeinfo.decNum);
    pMinPriceModel.model_openPrice = D_PriShow(pPriRes->priceData.fOpen, priceData->codeinfo.decNum);
    pMinPriceModel.model_prePrice = D_PriShow(priceData->fPre,priceData->codeinfo.decNum);
    pMinPriceModel.model_huanShouLv = SwpShow(pPriRes->priceData.nSwap);
    pMinPriceModel.model_liangBi = EPShow(priceData->nVolRate);
    pMinPriceModel.model_chengJiaoE = VolSumShow(priceData->lSum);
    pMinPriceModel.model_chengJiaoLiang = VolSumShow(pPriRes->priceData.lVol);
    pMinPriceModel.model_inPan = VolSumShow(priceData->lInSide);
    pMinPriceModel.model_outPan = VolSumShow(priceData->lOutSide);
    pMinPriceModel.model_weiBi = [NSString stringWithFormat:@"%.2f%%", priceData->nWeiBi/100.0];
    pMinPriceModel.model_weiCha = VolSumShow(priceData->lWeiCha);
    pMinPriceModel.model_shiYing = [NSString stringWithFormat:@"%.1f", priceData->nExePrice/10000.0];
    pMinPriceModel.model_avgPrice = [NSString stringWithFormat:@"%.2f", priceData->fAvgPrice];
    pMinPriceModel.model_zhangTing = [NSString stringWithFormat:@"%.2f", priceData->nRiseLimitPrice];
    pMinPriceModel.model_dieTing = [NSString stringWithFormat:@"%.2f", priceData->nDecLimitPrice];
    pMinPriceModel.model_currentNum = VolSumShow(priceData->lCurVol);
    
    //给分时增加现手
    [[NSNotificationCenter defaultCenter] postNotificationName:kMinCurVolNotification object:pMinPriceModel.model_currentNum];
    
    //五档
    HZWuDangModel *pBuyModel1 = [HZWuDangModel new];
    HZWuDangModel *pBuyModel2 = [HZWuDangModel new];
    HZWuDangModel *pBuyModel3 = [HZWuDangModel new];
    HZWuDangModel *pBuyModel4 = [HZWuDangModel new];
    HZWuDangModel *pBuyModel5 = [HZWuDangModel new];
    HZWuDangModel *pSellModel1 = [HZWuDangModel new];
    HZWuDangModel *pSellModel2 = [HZWuDangModel new];
    HZWuDangModel *pSellModel3 = [HZWuDangModel new];
    HZWuDangModel *pSellModel4 = [HZWuDangModel new];
    HZWuDangModel *pSellModel5 = [HZWuDangModel new];
    pBuyModel1.model_price = D_PriShow(priceData->fAsk,priceData->codeinfo.decNum);
    pBuyModel1.model_num = VolSumShow(priceData->lAskVol1);
    pBuyModel2.model_price = D_PriShow(priceData->fAskPri2,priceData->codeinfo.decNum);
    pBuyModel2.model_num = VolSumShow(priceData->lAskVol2);
    pBuyModel3.model_price = D_PriShow(priceData->fAskPri3,priceData->codeinfo.decNum);
    pBuyModel3.model_num = VolSumShow(priceData->lAskVol3);
    pBuyModel4.model_price = D_PriShow(priceData->fAskPri4,priceData->codeinfo.decNum);
    pBuyModel4.model_num = VolSumShow(priceData->lAskVol4);
    pBuyModel5.model_price = D_PriShow(priceData->fAskPri5,priceData->codeinfo.decNum);
    pBuyModel5.model_num = VolSumShow(priceData->lAskVol5);
    pSellModel1.model_price = D_PriShow(priceData->fBid,priceData->codeinfo.decNum);
    pSellModel1.model_num = VolSumShow(priceData->lBidVol1);
    pSellModel2.model_price = D_PriShow(priceData->fBidPri2,priceData->codeinfo.decNum);
    pSellModel2.model_num = VolSumShow(priceData->lBidVol2);
    pSellModel3.model_price = D_PriShow(priceData->fBidPri3,priceData->codeinfo.decNum);
    pSellModel3.model_num = VolSumShow(priceData->lBidVol3);
    pSellModel4.model_price = D_PriShow(priceData->fBidPri4,priceData->codeinfo.decNum);
    pSellModel4.model_num = VolSumShow(priceData->lBidVol4);
    pSellModel5.model_price = D_PriShow(priceData->fBidPri5,priceData->codeinfo.decNum);
    pSellModel5.model_num = VolSumShow(priceData->lBidVol5);
    
    NSArray *modelArray = [NSArray arrayWithObjects:
                           pSellModel5,
                           pSellModel4,
                           pSellModel3,
                           pSellModel2,
                           pSellModel1,
                           pBuyModel1,
                           pBuyModel2,
                           pBuyModel3,
                           pBuyModel4,
                           pBuyModel5, nil];
    pMinPriceModel.model_wuDangArray = modelArray;
    
    return pMinPriceModel;
}
//明细
+ (id)p_parseMingXiData
{
    QUOTELV_DETAIL_RES *pDetailRes = &g_pQuoteOper->DetailRes[QUOTELV_OPER_TAG_DETAIL];
    
    NSMutableArray *pTempArray = [NSMutableArray array];
    for (int i=10; i<pDetailRes->nTotalCount; i++) {
        HZMingXiModel *model = [HZMingXiModel new];
        QUOTELV_DETAIL_POINT *pPoint = &pDetailRes->detailData[i];
        char sTemp[128];
        memset(sTemp, 0, sizeof(sTemp));
        sprintf(sTemp, "%02d:%02d:%02d", pPoint->nDate/10000,pPoint->nDate%10000/100,pPoint->nDate%10000%100);
        model.model_time = [NSString stringWithUTF8String:sTemp];
        memset(sTemp, 0, sizeof(sTemp));
        if (pDetailRes->codeinfo.decNum==3) {
            sprintf(sTemp, "%.3f", pPoint->fPri);
        }else{
            sprintf(sTemp, "%.2f", pPoint->fPri);
        }
        model.model_price = [NSString stringWithUTF8String:sTemp];
        model.model_num = [NSString stringWithFormat:@"%@%c",VolSumShow(pPoint->lVol),pPoint->wind];
        model.model_priceColor = kMYGetZhangDieColor(pPoint->fPri, pDetailRes->fPre);
        if (pPoint->wind == 'B') {
            model.model_numColor = kREDColor;
        }else if (pPoint->wind == 'S') {
            model.model_numColor = kGREENColor;
        }
        
        [pTempArray addObject:model];
    }
    
    return pTempArray;
}
//分时
+ (void)p_parseMinData
{
    QUOTELV_TRADING_HOURS *pTradingHours1 = &g_pQuoteOper->tradeingHours;
    pTradingHours1->maxMinuteCount = 242;
    pTradingHours1->nMarketNum = 12;
    pTradingHours1->marketTrading[0].firstOpen = 930;
    pTradingHours1->marketTrading[0].firstClose = 1130;
    pTradingHours1->marketTrading[0].secodeOpen = 1300;
    pTradingHours1->marketTrading[0].secodeClose = 1500;
    pTradingHours1->marketTrading[0].marketID = 2;
    pTradingHours1->marketTrading[0].midscale = 1130;
    pTradingHours1->marketTrading[0].minuteCount = 242;
    
    pTradingHours1->marketTrading[1].firstOpen = 930;
    pTradingHours1->marketTrading[1].firstClose = 1130;
    pTradingHours1->marketTrading[1].secodeOpen = 1300;
    pTradingHours1->marketTrading[1].secodeClose = 1500;
    pTradingHours1->marketTrading[1].marketID = 1;
    pTradingHours1->marketTrading[1].midscale = 1130;
    pTradingHours1->marketTrading[1].minuteCount = 242;
}

+ (id)p_parseKLineData
{
    QUOTELV_K_RES *pKRes = &g_pQuoteOper->KRes[0];
    
    NSInteger num = pKRes->nMaxCount;
    QUOTELV_K_POINT *kPoint = &pKRes->kData[num - 1];
    float fPre = kPoint->fOpen;
    if (num >= 1) {
        QUOTELV_K_POINT *kPrePoint = &pKRes->kData[num - 2];
        fPre = kPrePoint->fCur;
    }
    HZMinPriceModel *model = [HZMinPriceModel new];
    model.model_currentPrice = D_PriShow(kPoint->fCur, "2");
    model.model_zhangDie = D_PriShowE(kPoint->fCur,fPre,"2");
    model.model_zhangFu = DRShow(kPoint->fCur, fPre);
    model.model_maxPrice = D_PriShow(kPoint->fHigh,"2");
    model.model_minPrice = D_PriShow(kPoint->fLow,"2");
    model.model_openPrice = D_PriShow(kPoint->fOpen, "2");
    model.model_prePrice = D_PriShow(fPre,"2");
    model.model_chengJiaoE = VolSumShow(kPoint->lSum/100);
    model.model_chengJiaoLiang = VolSumShow(kPoint->lVol);
    
    
    return model;
}

@end
